import java.util.Scanner;

public class PointExchange {
    public static void main(String[] args){
        MembershipPoints points=new MembershipPoints("asd",8000);
        System.out.println("本次可兑换的礼品如下：");
        System.out.println("1.加湿器  2.平底锅  3.电风扇");
        try{
            info_validation(points);
        }catch(MyException e){
            System.out.println(e.getMassage());
        }
    }

    public static void info_validation(MembershipPoints points)
            throws MyException{
        Scanner sc=new Scanner(System.in);
        int point=0;
        System.out.println("请输入要兑换的礼品的编号：");
        try{
            int giftorder=sc.nextInt();
            switch(giftorder){
                case 1:
                    point=1000;
                    break;
                case 2:
                    point=1500;
                    break;
                case 3:
                    point=2000;
                    break;
                default:
                    System.out.println("您输入的礼品的编号不存在！");
                    System.exit(0);
            }
        }catch(Exception e){
            throw new MyException("输入的礼品编号必须是数字！");
        }
        System.out.println("请输入您的会员编号：");
        String id=sc.next();
        if(id.equals(points.getMemberNum())){
            System.out.println("请输入您要兑换的数量：");
            try{
                int giftNum=sc.nextInt();
                if(giftNum>0){
                    if(giftNum*point<=points.getPoints()){
                        double shengyu=points.getPoints()-giftNum*point;
                        System.out.println("兑换成功！您剩余的积分为："+shengyu+"分");
                    }else{
                        System.out.println("积分不足，兑换失败！");
                    }
                }else{
                    System.out.println("兑换数量必须大于0");
                }
            }catch(Exception e){
                throw new MyException("输入的数量必须是数字！");
            }
        }else{
            System.out.println("您输入的会员编号不存在！");
        }
    }
}
